/*
 * @Author: xiaosihan
 * @Date: 2024-08-06 11:16:27
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-09-22 23:39:49
 */

import partsApi from "@api/partsApi";
import projectCollaborationApi from "@api/projectCollaborationApi";
import { get, isEmpty } from "lodash";
import { configure, observable } from "mobx";
configure({ enforceActions: "never" });

// 项目的分享弹窗
const projectShareModalStore = observable({
  show: false,
  setShow(show: boolean) {
    this.show = show;
  },

  projectId: "",
  shareId: "",
  shareToken: "",
  openShare: false,
  async getShareToken(projectId: string = "") {
    this.projectId = projectId;
    const res = await projectCollaborationApi.get_project_shareLink(projectId);
    const token = get(res, ["data", "shareId"]);
    const id = get(res, ["data", "id"]);
    const status = get(res, ["data", "status"]);
    this.shareId = id;
    this.shareToken = token;
    this.openShare = status === 1;
  },
  //关闭分享
  async closeShare() {
    await projectCollaborationApi.updateStatus_project_shareLink(
      this.shareId,
      0
    );
    this.getShareToken(this.projectId);
  },
  //打开分享链接
  async addShare() {
    await projectCollaborationApi.updateStatus_project_shareLink(
      this.shareId,
      1
    );
    this.getShareToken(this.projectId);
  },
});
export default projectShareModalStore;
